package javagprssrv.Listener;

import java.net.InetAddress;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class TrdDataSender_UDP extends java.lang.Thread
{
    java.lang.String DestIP;
    int DestPort;
    java.lang.String strSend;
    java.net.DatagramSocket socket;
    
    public TrdDataSender_UDP(final java.net.DatagramSocket _socket, final java.lang.String _DestIP, final int _DestPort, final java.lang.String _strSend) {
        super("TrdDataSender_UDP");
        this.DestIP = "";
        this.DestPort = -1;
        this.strSend = "";
        this.socket = _socket;
        this.DestIP = _DestIP;
        this.DestPort = _DestPort;
        this.strSend = _strSend;
    }
    
    @java.lang.Override
    public void run() {
        try {
            java.lang.Thread.sleep(1000L);
            final java.net.DatagramPacket DP = new java.net.DatagramPacket(this.strSend.getBytes(), this.strSend.getBytes().length);
            DP.setAddress(java.net.InetAddress.getByName(this.DestIP));
            DP.setPort(this.DestPort);
            final byte[] buf = new byte[this.strSend.length()];
            for (int i = 0; i < this.strSend.length(); ++i) {
                if (this.strSend.charAt(i) >= '\u0080') {
                    buf[i] = (byte)(this.strSend.charAt(i) - 'Ā');
                }
                else {
                    buf[i] = (byte)this.strSend.charAt(i);
                }
            }
            DP.setData(buf, 0, this.strSend.length());
            this.socket.send(DP);
        }
        catch (java.lang.Exception ex) {}
    }
}
